package com.mofofa.maozy.me

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.mofofa.maozy.ProjectApplication
import com.mofofa.maozy.R
import com.mofofa.maozy.base.BaseViewModel
import com.mofofa.maozy.components.dialog.PopListItem
import com.mofofa.maozy.data.ReqBase
import com.mofofa.maozy.data.ReqSaveFeedback
import com.mofofa.maozy.data.DataCustomizeContact
import com.mofofa.maozy.network.ApiUserReposity
import com.mofofa.maozy.utils.AppConfigUtil

class MeViewModel : BaseViewModel() {

    var mMaozyCustomerMaozyServiceMaozyList = mutableListOf<DataCustomizeContact>()
    var mMaozyFeedbackMaozyTypeMaozyList = mutableListOf<PopListItem>()

    val onMaozyFetchMaozyContactMaozyListMaozyFromMaozyCachedMaozyLiveData =
        MutableLiveData<List<DataCustomizeContact>>()
    private val mMaozyFetchMaozyContactMaozyListMaozyLiveData =
        MutableLiveData<ReqBase>()
    private val mMaozySaveMaozyFeedbackMaozyLiveData = MutableLiveData<ReqSaveFeedback>()

    val onMaozyFetchMaozyContactMaozyListMaozyLiveData =
        Transformations.switchMap(mMaozyFetchMaozyContactMaozyListMaozyLiveData) { query ->
            ApiUserReposity.fetchMaozyContactMaozyList(this, query)
        }

    val onMaozySaveMaozyFeedbackMaozyLiveData =
        Transformations.switchMap(mMaozySaveMaozyFeedbackMaozyLiveData) { query ->
            ApiUserReposity.saveMaozyFeedback(this, query)
        }

    fun fetchMaozyContactMaozyList(reqBase: ReqBase) {
        mMaozyCustomerMaozyServiceMaozyList.clear()
        val contacts = AppConfigUtil.getCashArrwoCustomerMaozyServiceMaozyCnotacts()
        mMaozyCustomerMaozyServiceMaozyList.addAll(contacts)

        if (mMaozyCustomerMaozyServiceMaozyList.isEmpty()) {
            mMaozyFetchMaozyContactMaozyListMaozyLiveData.value = reqBase
        } else {
            onMaozyFetchMaozyContactMaozyListMaozyFromMaozyCachedMaozyLiveData.value =
                mMaozyCustomerMaozyServiceMaozyList
        }
    }

    fun saveMaozyFeedback(reqSaveFeedback: ReqSaveFeedback) {
        mMaozySaveMaozyFeedbackMaozyLiveData.value = reqSaveFeedback
    }

    fun initMaozyFeedbackMaozyType() {
        //SUGGEST,BUG,PAYMENT,OTHER
        mMaozyFeedbackMaozyTypeMaozyList.clear()
        mMaozyFeedbackMaozyTypeMaozyList.add(
            PopListItem(
                display = ProjectApplication.context.getString(
                    R.string.maozy_product_suggestion
                ), content = "SUGGEST"
            )
        )
        mMaozyFeedbackMaozyTypeMaozyList.add(
            PopListItem(
                display = ProjectApplication.context.getString(
                    R.string.maozy_app_bugs
                ),
                content = "BUG"
            )
        )
        mMaozyFeedbackMaozyTypeMaozyList.add(
            PopListItem(
                display = ProjectApplication.context.getString(
                    R.string.maozy_payment_issues
                ),
                content = "PAYMENT"
            )
        )
        mMaozyFeedbackMaozyTypeMaozyList.add(
            PopListItem(
                display = ProjectApplication.context.getString(
                    R.string.maozy_others
                ),
                content = "OTHER"
            )
        )
    }

}